OUTPUT FORMATTING
#include <iomanip>
Important keywords (std before all of them):
-
setw(int) (ONLY FOR THE NEXT ONE)
-
The std::setw function allows you to set the minimum width of the next output via the insertion operator. setw takes, one argument, the width of the next output (insertion), an integer. if the next output is too short, then spaces will be used for padding. There is no effect if the output is longer than the width--note that the output won't be truncated.
-
left (default)
-
right
-
setfill(char) (FOR ALL THE REST)
-
You might wonder whether it is possible to change the padding character. It turns out that yes, you can, by using the setfill function, which takes a character to use for the padding. Note that setfill should also be used as a stream manipulator only, so it must be inserted into the stream:
-
setprecision(int)
-
if 3, 2.71828 becomes 2.71
-
setbase(int)